<template>
  <div class="layout-container">
    <!-- 左侧导航栏 -->
    <div class="sidebar">
      <el-menu class="sidebar-menu" :router="true" :default-active="activeMenu">
        <el-menu-item index="/user/profile/profile">
          <el-icon>
            <User />
          </el-icon>
          <span>个人信息</span>
        </el-menu-item>
        <el-menu-item index="/user/profile/favorites">
          <el-icon>
            <Star />
          </el-icon>
          <span>我的收藏</span>
        </el-menu-item>
        <el-menu-item index="/user/profile/fgfavorites">
          <el-icon>
            <Star />
          </el-icon>
          <span>国外菜谱收藏</span>
        </el-menu-item>
        <el-menu-item index="/user/profile/feedback">
          <el-icon>
            <ChatLineSquare />
          </el-icon>
          <span>我的反馈</span>
        </el-menu-item>
        <el-menu-item index="/user/profile/recipes">
          <el-icon>
            <Document />
          </el-icon>
          <span>我的菜谱</span>
        </el-menu-item>
        <el-menu-item index="/user/profile/orders">
          <el-icon>
            <List />
          </el-icon>
          <span>我的订单</span>
        </el-menu-item>
      </el-menu>
    </div>

    <!-- 右侧内容区 -->
    <div class="content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import {
  User,
  Star,
  ChatLineSquare,
  Document,
  List
} from '@element-plus/icons-vue'

const route = useRoute()
const activeMenu = ref(route.path)

// 当路由路径变化时，更新 activeMenu 的值
watch(
  () => route.path,
  (newPath) => {
    activeMenu.value = newPath
  }
)
</script>

<style scoped>
.layout-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 200px;
  background-color: #fff;
  border-right: 1px solid #dcdfe6;
}

.sidebar-menu {
  height: 100%;
  border-right: none;
}

.content {
  flex: 1;
  padding: 20px;
  background-color: #f5f7fa;
}

:deep(.el-menu-item) {
  display: flex;
  align-items: center;
}

:deep(.el-menu-item .el-icon) {
  margin-right: 8px;
}
</style>